package com.yun.datastructure.tree.binarysearchtree.leetcode;

import com.yun.datastructure.tree.binarytree.domain.TreeNode;

public class Leetcode235 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        TreeNode node=root;
        while (p.val< node.val&&q.val< node.val||node.val< p.val&&node.val<q.val){
            if(p.val< node.val){
                node=node.left;
            }else {
                node=node.right;
            }
        }
        return node;
    }
}
